package com.typhoon.spring_jdbctemplate.consumer;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.alibaba.fastjson.JSON;
import com.typhoon.spring_jdbctemplate.compare.CompareResult;
import com.typhoon.spring_jdbctemplate.entity.User;
import com.typhoon.spring_jdbctemplate.service.UserService;
import com.typhoon.spring_jdbctemplate.util.SpringContextUtil;

/**
 * 模拟用户信息对比客户端
 * 
 * @author Typhoon
 *
 */
public class UserCompareConsumer {

	public static void main(String[] args) throws ParseException {
		
		List<User> sourceList = new ArrayList<>(2);
		User u = new User();
		u.setName("aeolus");
		sourceList.add(u);
		u = new User();
		u.setId(2L);
		u.setName("typhoon");
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		u.setCreateTime(format.parse("2017-09-17 11:14:03"));
		sourceList.add(u);
		new ClassPathXmlApplicationContext("spring-root.xml").start();
		
		UserService userService = SpringContextUtil.getBean("userService", UserService.class);
		CompareResult<User>  result =  userService.compareUserList(sourceList);
		System.out.println(JSON.toJSONString(result));
	}

}
